﻿package com.views
{
    import com.*;
    import com.assist.server.*;
    import com.assist.view.*;
    import com.assist.view.info.*;
    import com.assist.view.interfaces.*;
    import com.assist.view.interfaces.map.*;
    import com.assist.view.map.*;
    import com.assist.view.sound.*;
    import com.haloer.net.*;
    import com.lang.client.com.views.*;
    import com.protocols.*;
    import com.views.map.*;
    import flash.display.*;
    import flash.utils.*;

    public class TownMapView extends MapViewBase
    {
        private var _Map:ITownMap;
        private var _guideLayder:Sprite;

        public function TownMapView()
        {
            this._guideLayder = new Sprite();
            return;
        }// end function

        public function init() : void
        {
            var _loc_1:* = MapStatic.mapInstance.town;
            this._Map = MapStatic.mapInstance.town;
            _mapBase = _loc_1;
            this._Map.upTipLayer = _structure.content;
            return;
        }// end function

        public function getPrestigeNo1PlayerId() : void
        {
            _data.call(Mod_WeekRanking_Base.get_week_ranking_first_player, getPrestigeBack, []);
            return;
        }// end function

        public function get guideLayder() : Sprite
        {
            return this._guideLayder;
        }// end function

        public function get townSign() : String
        {
            return TownType.getSign(_id);
        }// end function

        public function gotoTownAtId(param1:int = 0) : void
        {
            if (_view.missionPractice.inStageWithTip)
            {
                return;
            }
            if (_view.heroPractice.inStageWithTip)
            {
                return;
            }
            _view.screen.currentMap = this;
            _id = param1 || ctrlPlayer.townMapId || 1;
            _view.initLoading.tip = _loadTips[getTimer() % _loadTips.length];
            _view.initLoading.show();
            _view.initLoading.loading1(TownMapViewLang.Tip1);
            this.enter_town();
            return;
        }// end function

        private function infoComplete(param1:MapInfo) : void
        {
            _info = param1;
            _view.initLoading.loading1(TownMapViewLang.Tip2);
            File.loadList([_info.urlMini], this.miniMapLoaded);
            return;
        }// end function

        private function miniMapLoaded(param1:Array) : void
        {
            var _loc_3:String = null;
            var _loc_4:PortalInfo = null;
            var _loc_5:BuildInfo = null;
            var _loc_6:NPCInfo = null;
            _content.addChild(this._Map.content);
            _content.addChild(this._guideLayder);
            this._Map.backMini = param1[0].loader.content;
            this._Map.onMoveTo = move_to;
            this._Map.onNpcSpeak = this.onNpcSpeak;
            this._Map.onBuildClick = this.onBuildClick;
            this._Map.onPortal = this.onPortal;
            this._Map.onNpcRange = this.onNpcRange;
            this._Map.onMapClick = this.onMapClick;
            this._Map.onUpdateXY = this.onUpdateXY;
            this._Map.initMapinfo(_info);
            var _loc_2:* = TownType.getNPCList(_id);
            for (_loc_3 in _loc_2)
            {
                
                _loc_2[_loc_3].sign = _loc_3;
                _loc_6 = new NPCInfo(_loc_2[_loc_3]);
                if (_loc_6.type != NPCType.FactionGodNPC)
                {
                    this._Map.addNPC(_loc_6);
                }
            }
            for each (_loc_4 in _info.portals)
            {
                
                this._Map.addPortal(_loc_4);
            }
            for each (_loc_5 in _info.builds)
            {
                
                this._Map.addBuild(_loc_5);
            }
            this._Map.addPlayer(_playerInfo);
            this._Map.updateNpcLoack(_ctrl.player.functionLock);
            SoundManage.playBgSound(_info.urlSound);
            File.loadList([_info.urlMap], this.bgLoadedHandler(_id));
            this.enterMapComplete();
            return;
        }// end function

        private function bgLoadedHandler(param1:int) : Function
        {
            var townId:* = param1;
            return function (param1:Array) : void
            {
                if (inStage == false)
                {
                    return;
                }
                if (townId == _id)
                {
                    _Map.backSWF = param1[0].loader.content as IMapSWF;
                }
                return;
            }// end function
            ;
        }// end function

        public function quitJiHuiSuo() : void
        {
            if (ctrlPlayer.jihuisuoId != 0)
            {
                this.gotoTownAtId(ctrlPlayer.townMapId);
            }
            return;
        }// end function

        override protected function enterMapComplete() : void
        {
            super.enterMapComplete();
            get_players();
            _view.mapSwitched(MapViewBase.Town);
            _view.toolbar.miniMap.mapName = TownType.getName(_id);
            _view.toolbar.soundMute(SoundManage.mute == 0);
            if (ctrlPlayer.isEnterHeroMission)
            {
                ctrlPlayer.isEnterHeroMission = false;
                _view.heroMission.show();
            }
            if (_id == ctrlPlayer.jihuisuoId)
            {
                this._data.call(Mod_WorldFactionWar_Base.award_info, this.showAward, []);
            }
            return;
        }// end function

        private function showAward() : void
        {
            if (ctrlPlayer.jihuisuoId == _id)
            {
                if (_ctrl.worldFactionWar.awardInfo && _ctrl.worldFactionWar.awardInfo.is_have_award == 1 && _ctrl.worldFactionWar.awardInfo.is_can_receive == 1 && _ctrl.worldFactionWar.awardInfo.is_receive == 0)
                {
                    this._view.townMap.getBuildTarget(4).visible = true;
                    _view.tip.iTip.addTarget(this._view.townMap.getBuildTarget(4), WorldViewLang.FactionAwardTitle);
                }
                else
                {
                    _view.tip.iTip.removeTarget(this._view.townMap.getBuildTarget(4));
                    this._view.townMap.getBuildTarget(4).visible = false;
                }
            }
            return;
        }// end function

        public function playShuShangDrama() : void
        {
            SoundManage.playBgSound("");
            _view.drama.init(16777215, "YuJianFeiXing.xml");
            _view.drama.play(16777215, this.dramaEnd, true, 50);
            return;
        }// end function

        private function dramaEnd() : void
        {
            this.gotoTownAtId(TownType.getId(TownType.ShuShanCheng));
            return;
        }// end function

        protected function onMapClick(param1:Object, param2:int, param3:int) : void
        {
            _view.otherHead.info = param1 as PlayerInfo;
            _view.otherHead.show();
            _view.quest.haltWayFinding();
            return;
        }// end function

        private function onUpdateXY(param1:int, param2:int) : void
        {
            this._guideLayder.x = -param1;
            this._guideLayder.y = -param2;
            return;
        }// end function

        private function onPortal(param1:PortalInfo) : void
        {
            if (_view.tower.inStage)
            {
                return;
            }
            if (_view.serverWarCup.inStage)
            {
                return;
            }
            if (ctrlPlayer.jihuisuoId != 0)
            {
                this.gotoTownAtId(ctrlPlayer.townMapId);
            }
            else
            {
                _view.chooseMission.show();
            }
            _view.quest.finishWayFinding();
            return;
        }// end function

        public function moveToPortal(param1:Boolean = false) : void
        {
            if (inStage == false)
            {
                return;
            }
            this._Map.moveToPortal(param1);
            return;
        }// end function

        private function onNpcSpeak(param1:NPCInfo) : void
        {
            if (_view.missionPractice.inStageWithTip)
            {
                return;
            }
            if (_view.heroPractice.inStageWithTip)
            {
                return;
            }
            _view.npcDialog.townNPCId = param1.id;
            _view.npcDialog.npcSign = param1.sign;
            _view.npcDialog.switchSelf();
            return;
        }// end function

        private function onBuildClick(param1:BuildInfo) : void
        {
            if (param1.id == 1)
            {
                _view.factionBlessing.show();
            }
            else if (param1.id == 2)
            {
                _view.factionEat.joinEat();
            }
            else if (param1.id == 3)
            {
                _view.factionRollCake.switchSelf();
            }
            else if (param1.id == 4)
            {
                _data.call(Mod_WorldFactionWar_Base.receive_award, this.receiveAward, []);
            }
            return;
        }// end function

        private function receiveAward() : void
        {
            var _loc_2:String = null;
            var _loc_3:ItemInfo = null;
            var _loc_1:* = _ctrl.worldFactionWar.receiveAwardInfo;
            if (!_loc_1)
            {
                return;
            }
            if (_loc_1.result == Mod_WorldFactionWar_Base.SUCCESS)
            {
                _loc_2 = Lang.sprintf(WorldViewLang.ChampionContent, HtmlText.yellow("+" + _loc_1.fame), HtmlText.yellow("+" + _loc_1.coin), HtmlText.yellow("+" + _loc_1.stone));
                if (_loc_1.state_point != 0)
                {
                    _loc_2 = _loc_2 + ("," + HtmlText.yellow(WorldViewLang.StatePoint + _loc_1.state_point));
                }
                if (_loc_1.clothes_id != 0)
                {
                    _loc_3 = new ItemInfo();
                    _loc_3.parseSee(_loc_1.clothes_id);
                    _loc_2 = _loc_2 + ("," + HtmlText.yellow(_loc_3.name));
                }
                _view.alert.confirm(_loc_2, this.hiddenBuild);
            }
            else if (_loc_1.result == Mod_WorldFactionWar_Base.FULL_BAG)
            {
                _view.showTip(PackViewLang.PageFull);
            }
            else if (_loc_1.result == Mod_WorldFactionWar_Base.CAN_NOT_RECEIVE)
            {
                _view.showTip(WorldViewLang.CanNotReceive);
            }
            return;
        }// end function

        private function hiddenBuild(param1:uint) : void
        {
            _view.tip.iTip.removeTarget(_view.townMap.getBuildTarget(4));
            _view.townMap.getBuildTarget(4).visible = false;
            return;
        }// end function

        public function setBuildGetVisible(param1:int, param2:Boolean) : void
        {
            this._Map.setBuildGetVisible(param1, param2);
            return;
        }// end function

        public function getBuildTarget(param1:int) : Sprite
        {
            return this._Map.getBuildTarget(param1);
        }// end function

        private function onNpcRange(param1:NPCInfo) : void
        {
            var _loc_2:* = _view.npcDialog;
            if (param1 == null || _loc_2.townNPCId != param1.id)
            {
                _loc_2.close();
            }
            return;
        }// end function

        public function moveToNPCAtId(param1:int) : void
        {
            if (inStage == false)
            {
                return;
            }
            this._Map.moveToNPCAtId(param1);
            return;
        }// end function

        public function resetNPCHead(param1:Object) : void
        {
            if (inStage == false)
            {
                return;
            }
            this._Map.resetNPCHead(param1);
            return;
        }// end function

        public function set otherCount(param1:int) : void
        {
            if (inStage == false)
            {
                return;
            }
            this._Map.otherCount = param1;
            return;
        }// end function

        public function otherShow() : void
        {
            if (inStage == false)
            {
                return;
            }
            this._Map.otherVisible = true;
            return;
        }// end function

        public function otherHide() : void
        {
            if (inStage == false)
            {
                return;
            }
            this._Map.otherVisible = false;
            return;
        }// end function

        override protected function enter_town() : void
        {
            super.enter_town();
            var _loc_1:* = TownType.getSign(_id);
            var _loc_2:* = ctrlPlayer.level;
            ctrlMap.maxCount = 500;
            if (_loc_1 == TownType.XiaoYuCun && _loc_2 < 10)
            {
                ctrlMap.maxCount = 70;
            }
            return;
        }// end function

        override protected function enter_town_back() : void
        {
            var _loc_3:PlayerInfo = null;
            var _loc_1:* = ctrlMap.entownList;
            var _loc_2:int = 0;
            for each (_loc_2 in _loc_1)
            {
                
                _loc_3 = ctrlMap.getPlayerInfo(_loc_2);
                if (_playerInfo.id == _loc_2)
                {
                    if (ctrlMap.result == Mod_Town_Base.SUCCESS)
                    {
                        ctrlPlayer.setNewMapId(_id);
                        if (ctrlPlayer.jihuisuoId == _id && ctrlPlayer.isChampion)
                        {
                            getTownMapInfo(TownType.getSign(_id) + "_New", this.infoComplete);
                        }
                        else
                        {
                            getTownMapInfo(TownType.getSign(_id), this.infoComplete);
                        }
                        continue;
                    }
                    _view.alert.confirm(Lang.sprintf(TownMapViewLang.Tip4, TownType.getName(_id)), this.gotoTownAtId);
                }
            }
            return;
        }// end function

    }
}
